#include "KPF_DataManager.h"

#include <iostream>
using namespace std;

#include "KPF_StreamSession.h"

#include "log.h"

#include "oal_api.h"

#include "RunTime.h"

class CStreamClientSession : public KPF_StreamSession
{
public:
	CStreamClientSession( const int8_t *pIP, const int16u_t iPort )
		: KPF_StreamSession( pIP, iPort )
	{
		
	}
	
	int32_t handle_input( const KPF_Socket *pSocket, const int8u_t *pData, const int32_t iDataLen )
	{
		int32_t iRetCode = -1;
	
		if ( pData && iDataLen > 0 )
		{
			fwrite( pData, 1, iDataLen, stdout );
			fflush( stdout );
		
			iRetCode = 0;	
		}
	
		return iRetCode;
	}

protected:

private:

};

int main( int argc, char **argv )
{
	cout<<"main:-------------->"<<endl;
	
	KPF_StreamSession *pStreamClientSession = new CStreamClientSession( (const int8_t *)"127.0.0.1", 8000 );
	
	if ( pStreamClientSession )
	{
		char pWords[1024] = { 0x00, };
				
		while ( fgets( pWords, 1024, stdin ) )
		{

			pStreamClientSession->handle_output( pStreamClientSession->getSocket(  ), (const int8u_t *)pWords, strlen(pWords) );			

		}
	}
	
	while ( 1 )
		os_sleep( 1000 * 1000 * 60 );
		
	return 0;	
}

static CRunTime fg_RunTime;
